package com.promote.algorithm;

import java.util.Arrays;

/**
 * @ClassName MoveZeroes
 * Description 移动零
 * @Author LiZiHao
 * Date 2021/8/10 11:21
 * @Version 1.0
 **/
public class MoveZeroes {

    public static void moveZeroes(int[] nums) {

        int n = nums.length;
        int left = 0;
        int right = 0;


        while (right < n) {
            if (nums[right] != 0) {
                swap(nums,left,right);
                left++;
            }
            right++;

        }
        System.out.println(Arrays.toString(nums));
    }

    public static void swap(int[] nums,int left,int right) {
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }

    public static void main(String[] args) {
        int[] nums = {0,1,0,3,12};
        moveZeroes(nums);
    }
}
